package com.zbkj.front.controller;

import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.enquiry.ReportRequest;
import com.zbkj.common.request.project.ClientProjectDownloadRequest;
import com.zbkj.common.request.project.ClientProjectQueryRequest;
import com.zbkj.common.request.project.ClientProjectRequest;
import com.zbkj.common.request.project.ProjectDeliveryRequest;
import com.zbkj.common.response.CommonResult;
import com.zbkj.common.response.UploadResponse;
import com.zbkj.common.response.project.AiReportResponse;
import com.zbkj.common.response.project.ClientProjectInfoResponse;
import com.zbkj.common.response.project.EstimateRestProjectResponse;
import com.zbkj.common.response.project.ProjectTypeStatisticsResponse;
import com.zbkj.front.service.ProjectV2HandlerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Auther:
 * @Date: 2024/9/12 15:40
 * @Description:
 */
@CrossOrigin("*")
@RestController
@RequestMapping("api/front/project")
@Api(tags = "项目服务2")
public class ProjectV2Controller {

    @Autowired
    private ProjectV2HandlerService projectV2HandlerService;

    @ApiOperation(value="项目列表查询")
    @PostMapping("/projectList")
    public CommonResult<CommonPage<ClientProjectInfoResponse>> projectList(@RequestBody ClientProjectQueryRequest queryRequest) {
        System.out.println("hahhahahahahhahha");
        return CommonResult.success(CommonPage.restPage(projectV2HandlerService.projectList(queryRequest)));
    }

    @ApiOperation(value="项目资料上传")
    @PostMapping("/informationUpload/{type}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type",value = "材料类型：1 项目文件"),
    })
    public CommonResult<UploadResponse> informationUpload(@PathVariable("type") Integer type, MultipartFile file) {
        return CommonResult.success(projectV2HandlerService.informationUpload(type,file));
    }

    @ApiOperation(value="新建项目")
    @PostMapping("/createProjectBak")
    public CommonResult createProjectBak(@RequestBody @Validated({ClientProjectRequest.CreateProjectGroup.class})
                                      ClientProjectRequest projectRequest) {
        projectV2HandlerService.createProjectBak(projectRequest);
        return CommonResult.success();
    }

    @ApiOperation(value="新建项目")
    @PostMapping("/createProject")
    public CommonResult createProject(@RequestBody ClientProjectRequest projectRequest) {
        projectV2HandlerService.createProject(projectRequest);
        return CommonResult.success();
    }

    @ApiOperation(value="项目重新提交")
    @PostMapping("/resubmitProject")
    public CommonResult resubmitProject(@RequestBody @Validated({ClientProjectRequest.ResubmitProjectGroup.class})
                                        ClientProjectRequest projectRequest) {
        projectV2HandlerService.resubmitProject(projectRequest);
        return CommonResult.success();
    }

    @ApiOperation(value="获取项目信息")
    @GetMapping("/getProjectInfo/{projectId}")
    public CommonResult<ClientProjectInfoResponse> getProjectInfo(@PathVariable("projectId") Long projectId) {
        return CommonResult.success(projectV2HandlerService.getProjectInfo(projectId));
    }

    @ApiOperation(value="删除项目")
    @GetMapping("/delProject/{projectId}")
    public CommonResult delProject(@PathVariable("projectId") Long projectId) {
        projectV2HandlerService.delProject(projectId);
        return CommonResult.success();
    }

    @ApiOperation(value="查看估算结果")
    @GetMapping("/getEstimateResult/{projectId}")
    public CommonResult<EstimateRestProjectResponse> getEstimateResult(@PathVariable("projectId") Long projectId) {
        return CommonResult.success(projectV2HandlerService.getEstimateResult(projectId));
    }

    @ApiOperation(value="报告申请")
    @GetMapping("/reportApply/{projectId}")
    public CommonResult reportApply(@PathVariable("projectId") Long projectId) {
        //projectV2HandlerService.reportApply(projectId);
        return CommonResult.success();
    }

    @ApiOperation(value="估算资料下载")
    @PostMapping("/estimateFileDownload")
    public void estimateFileDownload(@RequestBody @Validated ClientProjectDownloadRequest downloadRequest, HttpServletResponse response) {
        projectV2HandlerService.estimateFileDownload(downloadRequest, response);
    }

    @ApiOperation(value="功能点明细导出文件下载")
    @GetMapping("/estimateFunFileDownload/{projectId}")
    public void estimateFunFileDownload(@PathVariable("projectId") Long projectId, HttpServletResponse response) {
        projectV2HandlerService.estimateFunFileDownload(projectId,response);
    }

    @ApiOperation(value="提交邮寄信息")
    @PostMapping("/commitDelivery/{projectId}")
    public CommonResult submitDelivery(@PathVariable("projectId") Long projectId,@RequestBody ProjectDeliveryRequest deliveryRequest) {
        if (!projectV2HandlerService.submitDelivery(projectId,deliveryRequest)) {
            return CommonResult.failed();
        }
        return CommonResult.success();
    }

    @ApiOperation(value="查看邮寄信息")
    @GetMapping("/getDeliveryInfo/{projectId}")
    public CommonResult getDeliveryInfo(@PathVariable("projectId") Long projectId) {
        return CommonResult.success(projectV2HandlerService.getDeliveryInfo(projectId));
    }

    @ApiOperation(value="提交AI扩写")
    @GetMapping("/submitAIHistory")
    public CommonResult submitAIHistory() {
        projectV2HandlerService.submitAIHistory();
        return CommonResult.success();
    }

    @ApiOperation(value="AI统计")
    @PostMapping("/aiReport")
    public CommonResult<AiReportResponse> aiReport(@RequestBody ReportRequest reportRequest) {
        return CommonResult.success(projectV2HandlerService.aiReport(reportRequest));
    }

    @ApiOperation(value="项目类别统计")
    @GetMapping("/projectTypeStatistics/{projectId}")
    public CommonResult<List<ProjectTypeStatisticsResponse>> projectTypeStatistics(@PathVariable("projectId") Long projectId) {
        return CommonResult.success(projectV2HandlerService.projectTypeStatistics(projectId));
    }
}
